package com.xaicode.learn.netty.inAndOutBoundHandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2021/6/20 0020 0:38
 */
@Slf4j
public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        final ChannelPipeline pipeline = ch.pipeline();

        // add inbound decoder
        pipeline.addLast(new NettyByte2LongDecoder());
        // add outbound encoder
        pipeline.addLast(new NettyLong2ByteEncoder());
        // add self handler
        pipeline.addLast(new NettyServerHandler());
    }
}
